﻿using System;
using System.Linq;
using System.Collections.Generic;

namespace Extensions
{
    public static class IEnumerable
    {        
        public static void Foreach<T>(this IEnumerable<T> enumberable, System.Action<T> visitor)
        {
            foreach (T current in enumberable)
            {
                visitor(current);
            }
        }
        public static void Foreach<T>(this IEnumerable<T> enumberable, Action<T, int> visitor)
        {
            int num = 0;
            foreach (T current in enumberable)
            {
                visitor(current, num++);
            }
        }
        public static bool IsEmpty<T>(this IEnumerable<T> enumberable)
        {
            return enumberable.Count<T>() == 0;
        }
        public static IEnumerable<List<T>> InSetsOf<T>(this IEnumerable<T> source, int max)
        {
            List<T> list = new List<T>(max);
            foreach (T current in source)
            {
                list.Add(current);
                if (list.Count == max)
                {
                    yield return list;
                    list = new List<T>(max);
                }
            }
            if (list.Any<T>())
            {
                yield return list;
            }
            yield break;
        }
    }
}
